import publicJS from "@/hook/public.js";
export default function (callBack = () => {}) {
	const {defaultImg} = publicJS();
	
	//左侧tabs配置类型
	const tabsList = [
		{name: '网站配置',value: 'web_config'},
		{name: '公司信息配置',value: 'company'},
		{name: '个性化页面配置',value: 'web_diy'},
		{name: 'seo配置',value: 'web_seo'},
		{name: '邮件配置',value: 'email'},
		{name: '其他',value: 'other'},
	];
	
	//数据类型
	const data_type = [
		{
			label: '单个数据 类型',
			options:[
				{label:'单行文本框',value:'input'},
				{label:'多行文本框',value:'textarea'},
				{label:'单选',value:'radio'},
				{label:'富文本',value:'editor'},
				{label:'单图',value:'img'},
			]
		},
		{
			label: '多个数据 类型',
			options:[
				{label:'多图',value:'imgs'},
				{label:'图文',value:'imgTextMultiple'},
				{label:'轮播',value:'shopSwiper'},
				{label:'底部菜单',value:'tabbarList'},
				{label:'文本键值对',value:'keyValue'},
				{label:'友情链接',value:'friendlyLink'},
				{label:'多行文本',value:'textMultiple'},
				{label:'颜色',value:'colors'},
			]
		}
	]

	
	//上传图片图片 给不同的组件图片字段赋值
	const imgSuccess = (res,pickImg,data) => {
		pickImg.show = false;
		switch(true){
		    case pickImg.name == 'iconPath':
				data.value[pickImg.valueIndex].iconPath = res.value
		        break;
		    case pickImg.name == 'selectedIconPath':
				data.value[pickImg.valueIndex].selectedIconPath = res.value
		        break;
			case pickImg.name == 'imgs':
				data.value[pickImg.valueIndex].img = res.value
			    break;
			case pickImg.name == 'img':
				data.value.img = res.value
			    break;
		    default:
				data.value = res.value;
		}
	}
	
	//添加配置，判断数据类型 给默认值
	const addSubFilter = (form)=>{
		switch(form.data_type){
			case 'imgs':
				form.arr = 'y';
				form.value = [{img: defaultImg}]
				break;
			case 'imgTextMultiple':
				form.arr = 'y';
				form.value = [{img: defaultImg}]
				break;
			case 'shopSwiper':
				form.arr = 'y';
				form.value = [{img: defaultImg}]
				break;	
			case 'tabbarList':
				form.arr = 'y';
				form.value = [{name: ''}]
				break;
			case 'keyValue':
				form.arr = 'y';
				form.value = [{name: ''}]
				break;
			case 'friendlyLink':
				form.arr = 'y';
				form.value = [{name: ''}]
				break;	
			case 'textMultiple':
				form.arr = 'y';
				form.value = [{name: ''}]
				break;
			case 'colors':
				form.arr = 'y';
				form.value = [{value: 'rgb(200,0,0)'}]
				break;
			case 'radio':
				form.value = 0; 
				break;
			case 'img':
				form.value = defaultImg; 
				break;
			default:
				form.notes = '';
				form.value = ''
		}
		form.sort ? form.sort : 0;
		if(form.arr == 'y')form.value = JSON.stringify(form.value)
		return form;
	}
	return {
		tabsList,
		data_type,
		imgSuccess,
		addSubFilter
	}
}